

export const getToken =()=>localStorage.getItem('token');
export const setToken =(str)=>{
  localStorage.setItem('token',str)
};
export const loyout =()=>{
  localStorage.removeItem('token');
  location.reload()
};

export const rejuctLocation =()=>{
  if(!getToken()){
    window.location.href='/#/login'
  }
}

export function getBase64(file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = () => resolve(reader.result);
    reader.onerror = error => reject(error);
  });
}

export const language=[
  {
    value:'chi',
    text:'中文'
  },
  {
    value:'eng',
    text:'English'
  },
  {
    value:'fre',
    text:'French'
  },
]
export const reg_money= /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
export const reg_money_scale= (v)=>new RegExp(`(^[1-9]([0-9]+)?(\\.[0-9]{1,${v}})?$)|(^(0){1}$)|(^[0-9]\\.[0-9]([0-9])?$)`)

export function getUrlParam( key) {
  const reg = new RegExp('[?&]' + key + '=([^&#]*)', 'i');
  const result = location.href.match(reg);
  return result ? result[1] : null;
}
